<template>
    <el-form label-width="40px" :model="DeviceCategory" ref="DeviceCategory_ref">
       <el-form-item label="名称" prop="DeviceCategoryName">
           <el-input v-model="DeviceCategory.DeviceCategoryName"></el-input>
       </el-form-item>
        <el-form-item label="上级"  prop="ParentId">
            <el-select v-model="DeviceCategory.ParentId" style="width: 100%">
                <el-option v-for="item in AllDeviceCategory" v-if="item.ParentId == 0" :value="item.Id" :label="item.DeviceCategoryName"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="编码"  prop="Code">
            <el-input  v-model="DeviceCategory.Code"></el-input>
        </el-form-item>
        <el-form-item label="备注"  prop="DeviceCategoryDescript">
            <el-input  v-model="DeviceCategory.DeviceCategoryDescript"></el-input>
        </el-form-item>
        <el-form-item align="center">
            <el-button type="warning" @click="AddSubmit">添加</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    export default {
        name: "AddDeviceCategory",
        props: {
            AllDeviceCategory: {
                type: Array,
                required: true
            }
        },
        data() {
            return {
                DeviceCategory: {
                    DeviceCategoryName: '',
                    ParentId: '',
                    Code: '',
                    DeviceCategoryDescript: '',
                }
            }
        },
        methods: {
            //数据提交
            AddSubmit() {
                let loadding = this.openLoading();
                if (this.DeviceCategory.ParentId == '') {
                    this.DeviceCategory.ParentId = 0 
                }
                this.$http.post('Device/AddDeviceCategoryContent', this.DeviceCategory).then(res => {
                    loadding.close();
                    if (res) {
                        this.$message.success('添加成功!')
                        this.form_resetField()

                        this.$parent.$parent.AddDeviceCategory_dialog = false
                        this.$parent.$parent.formdata()
                    } else {
                        this.$message.warning('添加失败,请重试!')
                    }
                })
            },
            //表格重置
            form_resetField() {
                this.$refs['DeviceCategory_ref'].resetFields()
            }
        }
    }
</script>

<style scoped>

</style>
